package net.pessu.android.shoppoid.gui;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.content.DialogInterface;
import android.widget.Toast;

public class TextChoicesContener {
	List<TextChoices> list = new ArrayList<TextChoices>();
	TextChoices currentTextChoices;

	Context context;

	public TextChoicesContener(Context currentContext) {
		this.context = currentContext;
	}

	public TextChoices addTextChoices(String titre, CharSequence[] data) {
		currentTextChoices = new TextChoices(context);
		currentTextChoices.init(titre, data,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int item) {
						Toast.makeText(context,
								currentTextChoices.getItems()[item],
								Toast.LENGTH_SHORT).show();
						currentTextChoices.setText(currentTextChoices
								.getItems()[item]);
						dialog.cancel();
					}
				});
		list.add(currentTextChoices);
		return currentTextChoices;
	}

	public void finaliseContener() {
		Iterator<TextChoices> spinners = list.iterator();
		while (spinners.hasNext()) {
			currentTextChoices = spinners.next();
			currentTextChoices
					.setClickItem(new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface arg0, int position) {
							for (TextChoices currentSpinner2 : list) {
								currentSpinner2.changeValue(position);
							}
							arg0.cancel();
						}
					});
		}
	}

}
